﻿using CodeFirst;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using ModelDto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBManager
{
    public class DbContextFactory : IDbContextFactory<MyDbContext>
    {
        private readonly IOptions<SystemAppSettings> _options;
        public DbContextFactory(IOptions<SystemAppSettings> _options)
        {
            this._options = _options;
        }
        public MyDbContext CreateDbContext()
        {
            var optionsBuilder = new DbContextOptionsBuilder<MyDbContext>();
            optionsBuilder.UseSqlServer(_options.Value.ConnectStrWrite);
            return new MyDbContext(optionsBuilder.Options);
        }
    }
}
